package se.topshelf.golftracker.core.domain;

import org.hibernate.validator.constraints.Range;

import javax.persistence.*;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 *
 */
@Entity
@Table(name  = "TeeBox")
public class TeeBox extends BaseEntity implements Comparable<TeeBox>{
    @ManyToOne
    private Hole hole;

    @NotNull  // Length of hole in meters when played from this tee box
    @Range(min = 0, max=1000)
    private Integer length;

    @NotNull
    @Enumerated(EnumType.STRING)
    private TeeColour teeColour;

    public TeeBox() {
    }

    public TeeBox(Integer length, TeeColour teeColour) {
        this.length = length;
        this.teeColour = teeColour;
    }

    public Hole getHole() {
        return hole;
    }

    public void setHole(Hole hole) {
        this.hole = hole;
    }

    public Integer getLength() {
        return length;
    }

    public void setLength(Integer length) {
        this.length = length;
    }

    public TeeColour getTeeColour() {
        return teeColour;
    }

    public void setTeeColour(TeeColour teeColour) {
        this.teeColour = teeColour;
    }

    @Override
    public String getGuiDescription() {
        return teeColour.getDescription() + " (" + length + " meters)";
    }

    public int compareTo(TeeBox o) {
        return teeColour.compareTo(o.getTeeColour());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TeeBox teeBox = (TeeBox) o;

        if (teeColour != teeBox.teeColour) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return teeColour.hashCode();
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("TeeBox");
        sb.append("{hole=").append(hole.getGuiDescription());
        sb.append(", length=").append(length);
        sb.append(", teeColour=").append(teeColour);
        sb.append('}');
        return sb.toString();
    }
}
